#!/bin/bash
set -e

# 生成版本号 如 backup_20240906135407.sql
if [ -z "$1" ]; then
    echo "请输入保存后sql文件名 如 backup_20240906135407.sql"
    exit 1
fi
version=$1
echo "版本号: $version"

if [ -z "$2" ]; then
    echo "请输入用户名 如 root"
    exit 1
fi
dbUser=$2

if [ -z "$3" ]; then
    echo "请输入密码 如 123456"
    exit 1
fi
dbPass=$3

if [ -z "$4" ]; then
    echo "请输入ip地址 如 localhost"
    exit 1
fi
dbHost=$4

if [ -z "$5" ]; then
    echo "请输入端口号 如 3306"
    exit 1
fi
dbPort=$5

if [ -z "$6" ]; then
    echo "请输入数据库名称 如 zyz"
    exit 1
fi
dbName=$6

if [ -z "$7" ]; then
    echo "请输入数据库docker容器名 如 zyz"
    exit 1
fi
mysqlContainer=$7

if [ -z "$8" ]; then
    echo "请输入数据库备份路径"
    exit 1
fi
backupPath=$8
# 备份mysql
# docker exec $mysqlContainer mysqldump -u$dbUser -p$dbPass -h $dbHost -P $dbPort $dbName > ./$backupPath/$version
mysqldump -u$dbUser -p$dbPass -h $dbHost -P $dbPort $dbName > ./$backupPath/$version

# docker exec mysql8 mysqldump -uroot -p123456 -h localhost -P 3306 zyz > ./$version

# # 获取当前日期
# current_date=$(date +%Y%m%d)

# docker exec mysql8 mysqldump -uroot -p123456 -h localhost -P 3306 zyz > ./mysql$current_date.sql